package com.bawei.controller;

import com.bawei.entity.User;
import com.bawei.service.UserService;
import com.bawei.vo.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user/")
public class UserController {
    @Autowired
    private UserService userService;

    /*分页列表*/
    @RequestMapping("list")
    public ResultEntity list(@RequestParam(defaultValue = "1")Integer current,@RequestParam(defaultValue = "3") Integer size, User user,String username){
        return ResultEntity.ok(userService.list(current,size,user,username));
    }

    /*添加*/
    @RequestMapping("save")
    public ResultEntity save(@RequestBody User user){

        try {
            userService.save(user);
            return ResultEntity.ok(true);
        }catch (Exception e){
            e.printStackTrace();
            return ResultEntity.ok(false);
        }
    }

    /*删除*/
    @RequestMapping("delete")
    public ResultEntity delete(Integer ids[]){

        try {
            userService.delete(ids);
            return ResultEntity.ok(true);
        }catch (Exception e){
            e.printStackTrace();
            return ResultEntity.ok(false);
        }
    }
}
